package 栈和队列;

import 抽象数据类型.ListNode;

import java.util.EmptyStackException;

public class LLQueue {
    private ListNode frontNode ;
    private ListNode rearNode;

    public LLQueue() {

    }

    public static  LLQueue initQueue(int[] arr) {
        LLQueue queue = new LLQueue();
        for (int i : arr) {
            queue.enQueue(i);
        }
        return queue;
    }

    public void enQueue(int data) {
        ListNode insertNode = new ListNode(data);
        if (rearNode != null) {
            rearNode.setNext(insertNode);
        }
        rearNode = insertNode;
        if (frontNode == null) {
            frontNode = rearNode;
        }
    }

    public boolean isEmpty() {
        return frontNode == null;
    }
    public int deQueue() {
        if (isEmpty()) {
            throw new EmptyStackException();
        }else{
            int val =(int) frontNode.getVal();
            frontNode = frontNode.next;
            return val;
        }
    }
    static  class Main{
        public static void main(String[] args) {
            int[] a = {1, 3, 4, 5, 9};
            LLQueue stack = LLQueue.initQueue(a);
            System.out.println(stack.deQueue());
        }
    }
}
